//	Project:	HexTower
//	File:		Direct3D_Manager.h
//	Author:		Mustafa Aldoori
//	Purpose:	Direct3D Manager to handle the Direct3D Device.

#pragma once

#include "UtilityManager.h"

// Direct3D9 Includes
#include <d3d9.h>
#include <d3dx9.h>
#include <tchar.h>

// Direct3D9 Libraries
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment (lib, "dxguid.lib")

class Direct3D_Manager
{
private:
	// Single static object of Direct3D_Manager
	static Direct3D_Manager		d3d_Instance;

	Direct3D_Manager( void );
	Direct3D_Manager( Direct3D_Manager &d3d );
	Direct3D_Manager &operator=( Direct3D_Manager &d3d );
	~Direct3D_Manager( void );

	LPDIRECT3D9					d3d_Direct3DObject;
	LPDIRECT3DDEVICE9			d3d_Direct3DDevice;
	LPD3DXSPRITE				d3d_Sprite;
	LPD3DXFONT					d3d_Font;
	LPD3DXLINE					d3d_Line;
	D3DPRESENT_PARAMETERS		d3d_PresentParams;


	HWND						d3d_hWnd;

public:
	// Singleton for Direct3D_Manager
	static Direct3D_Manager* GetInstance( void );

	LPDIRECT3D9						GetDirect3DObject( void )	{ return d3d_Direct3DObject; }
	LPDIRECT3DDEVICE9				GetDirect3DDevice( void )	{ return d3d_Direct3DDevice; }
	LPD3DXSPRITE					GetSprite( void )			{ return d3d_Sprite;		 }
	LPD3DXLINE						GetLine( void )				{ return d3d_Line;			 }
	const D3DPRESENT_PARAMETERS*	GetPresentParams( void )	{ return &d3d_PresentParams; }
	
	bool InitDirect3D( HWND hWnd, int nScreenWidth, int nScreenHeight, 
					   bool bIsWindowed = true, bool bVsync = true );

	bool DeviceBegin( void );
	bool DeviceEnd( void );
	bool SpriteBegin( void );
	bool SpriteEnd( void );
	bool LineBegin( void );
	bool LineEnd( void );

	void Present( void );
	void ShutdownDirect3D( void );
	void Clear( unsigned char ucRed = 0, unsigned char ucGreen = 0, unsigned char ucBlue = 0 );
	void ChangeDisplayParam( int nWidth, int nHeight, bool bWindowed );

	void DrawRect( RECT rRt, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue );
	void DrawLine( int nX1, int nY1, int nX2, int nY2, unsigned char ucRed = 255, unsigned char ucGreen = 255, unsigned char ucBlue = 255 );
	void DrawText( TCHAR *lpzText, int nX, int nY, unsigned char ucRed = 255, unsigned char ucGreen = 255, unsigned char ucBlue = 255 );

};

